package com.wdc.controller;

import com.wdc.common.BaseResponse;
import com.wdc.common.ErrorCode;
import com.wdc.common.ResultUtils;
import com.wdc.exception.BusinessException;
import com.wdc.model.domain.User;
import com.wdc.service.FollowService;
import com.wdc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/follow")
@Api("关注模块")
public class FollowController {


    @Resource
    private UserService userService;

    @Resource
    private FollowService followService;

    /**
     * 关注用户
     * @param id 要关注的用户id
     * @param request
     * @return
     */
    @PostMapping("/{id}")
    @ApiOperation("关注用户")
    public BaseResponse<String> followUser(@PathVariable  Long id, HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        if (loginUser == null){
            throw new BusinessException(ErrorCode.NOT_LOGIN);
        }
        followService.followUser(id,loginUser.getId());
        return ResultUtils.success("ok");

    }


}
